package com.dd.ent.car.ui.user.note;

import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;

import com.dd.ent.car.AppContext;
import com.dd.ent.car.common.bean.base.PageBean;
import com.dd.ent.car.common.bean.base.ResultBean;
import com.dd.ent.car.common.bean.note.Note;
import com.dd.ent.car.common.config.UIConfig;
import com.dd.ent.car.service.note.NoteService;
import com.dd.ent.car.service.user.UserService;
import com.dd.ent.car.ui.adapter.base.BaseListAdapter;
import com.dd.ent.car.ui.home.templet.HomeTempletListFragment;
import com.google.gson.reflect.TypeToken;
import com.pp.ent.base.log.MLog;
import com.pp.ent.core.manage.UIHandler;
import com.pp.ent.view.annotation.Inject;

import java.lang.reflect.Type;


/**
 * 精选界面
 */
public class UserNoteFragment extends HomeTempletListFragment<Note> {
    private final static String TAG = "ChoiceFragment";

    @Inject
    private NoteService noteService;
    @Inject
    private UserService userService;
    private boolean isFirst = true;


    public static UserNoteFragment getInstance(UserNoteActivity.Type type){
        Bundle bundle =new Bundle();
        bundle.putSerializable(UserNoteActivity.TYPE,type);
        UserNoteFragment userNoteFragment = new UserNoteFragment();
        userNoteFragment.setArguments(bundle);
        return userNoteFragment;

    }
    @Override
    protected void initWidget(View root) {
        super.initWidget(root);
        mRefreshLayout.setEnabled(false);
    }

    @Override
    protected void initData() {
        super.initData();
        requestData();

    }

    @Override
    public void onRefreshing() {
        super.onRefreshing();
        if (!isFirst)
            getBannerList();
    }

    @Override
    protected void requestData() {
        super.requestData();
        noteService.getVideoByUid(userService.getUid());
    }

    @Override
    protected BaseListAdapter<Note> getListAdapter() {
        return new UserNoteAdapter(this);
    }

    @Override
    protected Type getType() {
        return new TypeToken<ResultBean<PageBean<Note>>>() {
        }.getType();
    }

    @Override
    protected void onRequestFinish() {
        super.onRequestFinish();
        isFirst = false;
    }

    @Override
    protected void setListData(ResultBean<PageBean<Note>> resultBean) {
        // ((ChoiceAdapter) mAdapter).setSystemTime(resultBean.getTime());
        super.setListData(resultBean);
    }

    private void getBannerList() {
    }


    @UIHandler(UIConfig.GET_NOTE_INFO_BY_UID_SUCCESS)
    public void getListChocieRes(String json) {
        MLog.debug(TAG, "getListChocieRes json=" + json);
        ResultBean<PageBean<Note>> resultBean = AppContext.createGson().fromJson(json, getType());
        setListData(resultBean);
        onRequestFinish();

    }
}
